<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend style="font-size:medium;">编辑通知公告</legend>
        </fieldset>
        <form class="layui-form" action="">
            <input type="hidden" name="id">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" style="width:1000px" id="title" lay-verify="required"
                        lay-reqtext="标题不能为空" placeholder="请输入标题" class="layui-input" spellcheck="false">
                </div>
            </div>
          <!-- style="display: none;" -->
          <div class="layui-form-item">   
            <label class="layui-form-label ">是否置顶</label>
            <div class="layui-input-block" style="width:1000px;">
                <select id="isTop" style="z-index: 9;">
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
            </div>
            <!-- <label class="layui-form-label">选择分类</label>
            <div class="layui-input-block" style="width:1000px;">
                <select id="noticeSort">
                </select>
                <br>
            </div> -->
        </div>
        <br>
            <div class="layui-form-item">
                <label class="layui-form-label required">全文</label>
                <div class="layui-input-block">
                    <!-- <textarea name="text" id="text" lay-verify="required" class="layui-textarea" placeholder="请输入全文"
                        style="width:1000px;height: 210px;" spellcheck="false"></textarea> -->
                    <div class="editorBox" id="editorIdNoticeEdit" name="gdesc" style="width: 1000px;min-height:360px;"></div>    
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="submit" lay-submit lay-filter="saveBtn" style="position:absolute;right:18%;bottom:2px;border:none;outline:none;width: 90px;height:32px;line-height:32px;
                    background-color: #FFB800;font-size: 14px;color: #ffffff;">修改</button>
                    <button class="layui-btn" onclick="closetEditNotice();" type="button" style="position:absolute;right:8%;bottom:2px;border:none;outline:none;width: 90px;height:32px;line-height:32px;
                    background-color: #cccccc;font-size: 14px;color: #ffffff;">关闭</button>
                </div>
            </div>
        </form>
    </div>
</div>


<!-- 富文本 -->
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.config.js"></script>
<!-- <script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.all.min.js"></script> -->
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/lang/zh-cn/zh-cn.js"></script>
<style>
     .layui-form-select dl{
        z-index: 9999;
    }
</style>
<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('editorIdNoticeEdit', {
            autoHeightEnabled: true,
            autoFloatEnabled: true,
            enableAutoSave: false,
            allowDivTransToP: false,//阻止div标签自动转换为p标签
            toolbars: [[
                'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'insertimage', 'emotion', 'attachment', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
                'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                'preview', 'searchreplace', 'drafts', 'help'
            ]]
        });

    ue.ready(function () {
            //富文本跨域解决
            if(typeof(UE_Config_Json_LKJHGFDSA)!="undefined"){
                UE.utils.extend(ue.options, UE_Config_Json_LKJHGFDSA);
            }
        });
</script>
<script type="text/javascript">
    $(function () {
         //渲染分类下拉框
         shared.ajaxGet('/admin/notice/getNoticeSort', { }, function (res) {
                var r = '';
                for (var i = 0; i < res.length; i++) {
                    r += '"<option value=' + res[i].sortCode + '>' + res[i].sortShowName +
                        '</option>"';
                }
                $("#noticeSort").html(r);
              
                if (parent.opreatType == "edit") {
                    var parent_json = parent.editData;
                    $("input[name='id']").val(parent_json.id)
                    $("input[name ='title']").val(parent_json.title)
                    // $("textarea[name ='text']").val(parent_json.text)
                    ue.ready(function() {
                    ue.setContent(parent_json.text);
                    });
                    $("#isTop").val(parent_json.isTop)
                    $("#noticeSort").val(parent_json.sortCode)
                }
                layui.form.render("select");
            });
   
    });

    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        form.render();

        var parentIndex = layer.index;
        


        //监听提交
        layui.form.on('submit(saveBtn)', function (data) {
            var id = $("input[name='id']").val(),
                isTop = $("#isTop").val(),
                // noticeSort = $("#noticeSort").val(),
                // sortShowName = $("#noticeSort option:selected").text();
                noticeSort ="A",
                sortShowName = "通知";
                title = $("#title").val(),
                // text = $("#text").val();
                text= ue.getContent();
                shared.ajaxPost('/admin/notice/updateNotice',
                    {
                        id: id,
                        isTop: isTop,
                        noticeSort: noticeSort,
                        sortShowName: sortShowName,
                        title: title,
                        text: text
                    },
                    function (res) {
                        layer.close(parentIndex);
                        $('#submit').attr('disabled', true);
                        refreshTable();
                    })
                return false;
            
        });

        //更新后刷新表格
        function refreshTable() {
            cols = [
                { align: 'center', title: '序号', type: 'numbers', width: '5%' },
                { field: 'id', title: 'ID', width: '8%', hide: true },
                { field: 'title', title: '标题', align: 'center', width: '40%' },
                { field: 'senderName', title: '发布用户', align: 'center', width: '10%' },     
                { field: 'isTop', title: '是否置顶', align: 'center', width: '10%' },
                // { field: 'sortCode', title: '分类code', align: 'center', hide: true },
                // { field: 'sortShowName', title: '分类名', align: 'center', width: '10%' },
                { field: 'sendTime', title: '发布时间', align: 'center', width: '20%'},
                { field: 'text', title: '全文', align: 'center', hide: true },
                { title: '操作', templet: '#currentTableBar',align: "center"}
            ];

            layuiEx.tableRender('/admin/notice/queryNotice', 'currentTableId', 'page', cols, {
                page: 1,
                pageSize: 10,
            });
        }
    });

       /** 设置关闭按钮的click事件处理 */
       function closetEditNotice() {
        layer.confirm('确定丢弃编辑页面内容？', function (index) {
            layer.closeAll();
        });
    }
</script>